package palmtop.com.palmtop.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.LinearLayout;

import com.beardedhen.androidbootstrap.AwesomeTextView;

import net.grandcentrix.tray.AppPreferences;

import java.util.ArrayList;

import palmtop.com.palmtop.R;
import palmtop.com.palmtop.activity.PopulationdetailActivity;
import palmtop.com.palmtop.model.Reportpopulation;
import palmtop.com.palmtop.util.BadgeView;

/**
 * Created by Administrator on 2017/9/1.
 */

public class PopulationAdapter extends BaseAdapter {
    private ArrayList<Reportpopulation> arrlist;
    private Context context;
    String role_id;

    public PopulationAdapter(ArrayList<Reportpopulation> arrlist, Context context) {
        this.arrlist = arrlist;
        this.context = context;
        AppPreferences appPreferences = new AppPreferences(context);
        role_id = appPreferences.getString("role_id","");
    }

    @Override
    public int getCount() {
        return arrlist.size();
    }

    @Override
    public Object getItem(int i) {
        return arrlist.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int pos, View view, ViewGroup viewGroup) {
        view = LayoutInflater.from(context).inflate(R.layout.item_population,null);
        LinearLayout lay1 = view.findViewById(R.id.lay1);
        LinearLayout lay2 = view.findViewById(R.id.lay2);
        final AwesomeTextView taskname1 = view.findViewById(R.id.taskname1);
        lay1.setVisibility(View.VISIBLE);
        lay2.setVisibility(View.GONE);

        AwesomeTextView status = view.findViewById(R.id.status);
//        AwesomeTextView reportman = view.findViewById(R.id.reportman);
        AwesomeTextView addtime = view.findViewById(R.id.addtime);
        AwesomeTextView palcetypename = view.findViewById(R.id.placetypename);


        Button xiangqing = view.findViewById(R.id.xiangqing);

        final Reportpopulation reportpopulation = arrlist.get(pos);



        if(role_id.equals("73006b03b7f447bf953d065462e5b1ac")){
            if(!reportpopulation.getReadflag().equals("1")){
                BadgeView badge = new BadgeView(context,taskname1);
                badge.setText("未读");
                badge.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);
                badge.show();
            }
        }


        palcetypename.setText(reportpopulation.getPalcetypename());
//        reportman.setText(reportpopulation.getReportman());
        if(reportpopulation.getStatus().equals("1")){
            status.setText("民警已采纳");
        }else if(reportpopulation.getStatus().equals("2")){
            status.setText("民警未采纳");
        }else{
            status.setText("待确认");
        }
        addtime.setText(reportpopulation.getAddtime());
        xiangqing.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.putExtra("reportpopulation",reportpopulation);
                intent.setClass(context,PopulationdetailActivity.class);
                context.startActivity(intent);
            }
        });



        return view;
    }
}
